package com.yipao.db.service.devinfo;

import com.yipao.db.dao.dev.DevGoodsMapper;
import com.yipao.db.domain.goods.DevGoods;
import com.yipao.db.util.DeleteStatusConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 设备产品
 *
 * @author tianhao
 */
@Service
public class DevGoodsService {
    @Resource
    private DevGoodsMapper devGoodsMapper;

    /**
     * 商品和设备绑定
     *
     * @param devGoods
     * @return int
     */
    public int insert(DevGoods devGoods) {
        devGoods.setAddTime(LocalDateTime.now());
        devGoods.setUpdateTime(devGoods.getAddTime());
        devGoods.setDeleted(DeleteStatusConstant.NOT_DELETED);
        return devGoodsMapper.insert(devGoods);
    }

    /**
     * 批量新增
     *
     * @param devId    设备id
     * @param goodsIds 商品id
     * @return
     */
    public int insertBatch(String devId, List<Integer> goodsIds) {
        DevGoods devGoods = new DevGoods();
        devGoods.setAddTime(LocalDateTime.now());
        devGoods.setUpdateTime(devGoods.getAddTime());
        devGoods.setDevId(devId);
        devGoods.setDeleted(DeleteStatusConstant.NOT_DELETED);
        return devGoodsMapper.insertBatch(devGoods, goodsIds);
    }

    /**
     * 修改设备产品的删除状态
     *
     * @param id
     * @return
     */
    public int updateDevGoodsDeleteStatus(Integer id) {
        DevGoods devGoods = new DevGoods();
        devGoods.setId(id);
        devGoods.setDeleted(DeleteStatusConstant.IS_DELETED);
        devGoods.setUpdateTime(LocalDateTime.now());
        return devGoodsMapper.updateDevGoodsDeleteStatus(devGoods);
    }

    /**
     * 修改设备产品的删除状态
     *
     * @param devId 设备id
     * @return
     */
    public int updateDevGoodsDeleteStatus(String devId) {
        DevGoods devGoods = new DevGoods();
        devGoods.setDevId(devId);
        devGoods.setDeleted(DeleteStatusConstant.IS_DELETED);
        devGoods.setUpdateTime(LocalDateTime.now());
        return devGoodsMapper.updateDevGoodsDeleteStatusByDevId(devGoods);
    }

    /**
     * 修改
     *
     * @param devGoods
     * @return
     */
    public int update(DevGoods devGoods) {
        devGoods.setUpdateTime(LocalDateTime.now());
        return devGoodsMapper.update(devGoods);
    }

    public List<DevGoods>selectByDevId(Integer devId){
        return devGoodsMapper.selectByDevId(devId);
    }



    public Integer findNumByDevId(String devId ){
        return devGoodsMapper.findNumByDevId(devId);
    }






}
